#!/usr/bin/perl
#Programmer: Rory Carmichael
#Purpose: Convert a min-max file into its ldist representation
#Usage: rc-mm-to-ldist.pl <min_max file> 

while (my $line = <>) {
	chomp $line;
	if ($line =~ />/) {
		print $line . "\n";
	} else {
		my @ldists = ();
		my $l_index = -1;
		my @splitline = split(/,/, $line);
		my $i=0;
		while ($i <= $#splitline) {
			if($splitline[$i] <= 0) {
				$l_index = $i;
				$ldists[$l_index] = 1;
				$i++;
				while ($splitline[$i] <= 0 && $i < $#splitline) {
					$ldists[$i] = 0;
					$ldists[$l_index] ++;
					$i++;
				}
			} else {
				$ldists[$i] = 0;
				$i++;
			}
		}
		print join(",", @ldists) . "\n";
	}
}
